package com.Questions.DFS;


/**
 * 路径总和
 */
public class leetcode112 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if(root == null) {
            return false;
        }
        return findTarget(root, targetSum);
    }
    public boolean findTarget(TreeNode root, int target) {
        if (root.right == null && root.left == null) {
            if(target == root.val) {
                return true;
            }else{
                return false;
            }
        }
        boolean leftRet = false;
        boolean rightRet = false;
        if (root.left != null){
            leftRet = findTarget(root.left,target - root.val);
        }
        if (root.right != null) {
            rightRet = findTarget(root.right,target - root.val);
        }
        if(leftRet || rightRet){
            return true;
        }else{
            return false;
        }

    }
}
